<template>
  <div class="">
    <el-form ref="form" :model="configFormData" label-width="180px">
      <el-form-item
        label="修改API地址"
        v-if="configFormData.method === 'set_api_url'"
      >
        <el-input v-model="configFormData.url"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="configFormData.pswd"></el-input>
      </el-form-item>
      <el-form-item
        label="是否允许用户填写"
        v-if="configFormData.method === 'set_app_status'"
      >
        <el-switch v-model="configFormData.open"></el-switch>
      </el-form-item>
      <el-form-item>
        <el-radio v-model="configFormData.method" label="set_api_url"
          >修改api地址</el-radio
        >
        <el-radio v-model="configFormData.method" label="set_app_status"
          >修改状态</el-radio
        >
      </el-form-item>
      <el-button
        type="success"
        size="large"
        style="margin-top: 30px; margin-left: 20%"
        @click="handleCommit"
        v-loading="isLoading"
      >
        提交</el-button
      >
    </el-form>
  </div>
</template>

<script>
import Axios from 'axios'
export default {
  name: 'Config',
  data() {
    return {
      configFormData: {
        url: '',
        pswd: '',
        open: false,
        method: 'set_api_url'
      },
      isLoading: false
    }
  },
  methods: {
    async handleCommit() {

      this.isLoading = true
      const axiso_ = Axios.create({
        baseURL: 'http://form.51web.club',
        withCredentials: false
      })
      let param = this.configFormData.method == 'set_app_status'?(this.configFormData.open?"on":"off"):this.configFormData.url;
      const { data } = await axiso_(`config/setup.php?pswd=${ this.configFormData.pswd }&param=${ param }&method=${ this.configFormData.method }`)
      console.log(data)
      if (data.code === 1) {
        this.$message.success('修改成功')

      }
      this.isLoading = false
    }
  }
}
</script>

<style>
</style>
